package com.breeze.media.image

import android.content.Context
import android.graphics.*
import android.util.AttributeSet
import android.view.View
import com.breeze.media.R


class ColorFilterView @JvmOverloads constructor(
    context: Context,
    attrs: AttributeSet?,
    defStyleAttr: Int = 0
) : View(context, attrs, defStyleAttr) {
    private var paint = Paint()
    private var bitmap: Bitmap = BitmapFactory.decodeResource(resources, R.drawable.person)
    private var colorFilter: ColorFilter = LightingColorFilter(0xffffff, 0x00ff00)
    private var mMatrix = Matrix()

    fun setColorFilter(colorFilter: ColorFilter) {
        this.colorFilter = colorFilter
        invalidate()
    }

    override fun onDraw(canvas: Canvas?) {
        super.onDraw(canvas)
        //画原图
        paint.colorFilter = colorFilter
        canvas?.drawBitmap(bitmap, mMatrix, paint)
    }
}